'''
Algorithm Contest Template - Python
Author: Ethan Cheung
Last Updated: 2025-10-08


███████╗████████╗██╗░░██╗░█████╗░███╗░░██╗░█████╗░██╗░░██╗███████╗██╗░░░██╗███╗░░██╗░██████╗░
██╔════╝╚══██╔══╝██║░░██║██╔══██╗████╗░██║██╔══██╗██║░░██║██╔════╝██║░░░██║████╗░██║██╔════╝░
█████╗░░░░░██║░░░███████║███████║██╔██╗██║██║░░╚═╝███████║█████╗░░██║░░░██║██╔██╗██║██║░░██╗░
██╔══╝░░░░░██║░░░██╔══██║██╔══██║██║╚████║██║░░██╗██╔══██║██╔══╝░░██║░░░██║██║╚████║██║░░╚██╗
███████╗░░░██║░░░██║░░██║██║░░██║██║░╚███║╚█████╔╝██║░░██║███████╗╚██████╔╝██║░╚███║╚██████╔╝
╚══════╝░░░╚═╝░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝╚══════╝░╚═════╝░╚═╝░░╚══╝░╚═════╝░

slogan: "Every commit is a step closer — EthanCheung keeps climbing."

'''

import sys
import math
import random
import bisect
import heapq
from math import *
from collections import *
from typing import *
from itertools import *


# =============================================================================
# TYPE ALIASES
# =============================================================================

# Type aliases for better readability
I = int
F = float
S = str
B = bool
List = list
Tuple = tuple
Dict = dict
Set = set
Optional = Optional

# =============================================================================
# MATHEMATICAL UTILITIES
# =============================================================================

class MathUtils:
    @staticmethod
    def gcd(a: I, b: I) -> I:
        """Greatest Common Divisor"""
        while b:
            a, b = b, a % b
        return a
    
    @staticmethod
    def lcm(a: I, b: I) -> I:
        """Least Common Multiple"""
        return a * b // MathUtils.gcd(a, b)
    
    @staticmethod
    def extended_gcd(a: I, b: I) -> Tuple[I, I, I]:
        """Extended Euclidean Algorithm"""
        if b == 0:
            return a, 1, 0
        gcd, x1, y1 = MathUtils.extended_gcd(b, a % b)
        return gcd, y1, x1 - (a // b) * y1
    
    @staticmethod
    def mod_pow(base: I, exp: I, mod: I = 10**9 + 7) -> I:
        """Modular exponentiation"""
        result = 1
        base %= mod
        while exp > 0:
            if exp & 1:
                result = (result * base) % mod
            base = (base * base) % mod
            exp >>= 1
        return result
    
    @staticmethod
    def mod_inverse(a: I, mod: I = 10**9 + 7) -> I:
        """Modular inverse using Fermat's little theorem"""
        return MathUtils.mod_pow(a, mod - 2, mod)
    
    @staticmethod
    def is_prime(n: I) -> B:
        """Miller-Rabin primality test"""
        if n < 2:
            return False
        small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
        for p in small_primes:
            if n % p == 0:
                return n == p
        
        d = n - 1
        s = 0
        while d % 2 == 0:
            d //= 2
            s += 1
        
        for a in small_primes:
            if a >= n:
                continue
            x = MathUtils.mod_pow(a, d, n)
            if x == 1 or x == n - 1:
                continue
            for _ in range(s - 1):
                x = (x * x) % n
                if x == n - 1:
                    break
            else:
                return False
        return True
    
    @staticmethod
    def sieve(n: I) -> List[I]:
        """Sieve of Eratosthenes"""
        sieve = [True] * (n + 1)
        sieve[0] = sieve[1] = False
        for i in range(2, int(n**0.5) + 1):
            if sieve[i]:
                sieve[i*i::i] = [False] * len(sieve[i*i::i])
        return [i for i, prime in enumerate(sieve) if prime]

# =============================================================================
# DATA STRUCTURES
# =============================================================================

class DSU:
    """Disjoint Set Union (Union-Find) with path compression and union by size"""
    def __init__(self, n: I):
        self.parent = list(range(n))
        self.size = [1] * n
    
    def find(self, x: I) -> I:
        while x != self.parent[x]:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x
    
    def union(self, x: I, y: I) -> B:
        x_root = self.find(x)
        y_root = self.find(y)
        if x_root == y_root:
            return False
        if self.size[x_root] < self.size[y_root]:
            x_root, y_root = y_root, x_root
        self.parent[y_root] = x_root
        self.size[x_root] += self.size[y_root]
        return True
    
    def connected(self, x: I, y: I) -> B:
        return self.find(x) == self.find(y)

class FenwickTree:
    """Fenwick Tree (Binary Indexed Tree) for range sum queries"""
    def __init__(self, size: I):
        self.n = size
        self.tree = [0] * (size + 1)
    
    def update(self, index: I, delta: I):
        while index <= self.n:
            self.tree[index] += delta
            index += index & -index
    
    def query(self, index: I) -> I:
        result = 0
        while index > 0:
            result += self.tree[index]
            index -= index & -index
        return result
    
    def range_query(self, left: I, right: I) -> I:
        return self.query(right) - self.query(left - 1)

class SegmentTree:
    """Segment Tree for range queries"""
    def __init__(self, data: List[I], function=max):
        self.n = len(data)
        self.size = 1
        while self.size < self.n:
            self.size <<= 1
        self.tree = [0] * (2 * self.size)
        self.function = function
        self.build(data)
    
    def build(self, data: List[I]):
        for i in range(self.n):
            self.tree[self.size + i] = data[i]
        for i in range(self.size - 1, 0, -1):
            self.tree[i] = self.function(self.tree[2*i], self.tree[2*i + 1])
    
    def query(self, left: I, right: I) -> I:
        left += self.size
        right += self.size
        result = float('-inf') if self.function == max else float('inf')
        while left <= right:
            if left % 2 == 1:
                result = self.function(result, self.tree[left])
                left += 1
            if right % 2 == 0:
                result = self.function(result, self.tree[right])
                right -= 1
            left //= 2
            right //= 2
        return result
    
    def update(self, index: I, value: I):
        index += self.size
        self.tree[index] = value
        index //= 2
        while index > 0:
            self.tree[index] = self.function(self.tree[2*index], self.tree[2*index + 1])
            index //= 2

class TrieNode:
    """Trie Node implementation"""
    __slots__ = ['children', 'is_end']
    def __init__(self):
        self.children: Dict[S, 'TrieNode'] = {}
        self.is_end: B = False

class Trie:
    """Trie implementation for efficient string operations"""
    def __init__(self):
        self.root = TrieNode()
    
    def insert(self, word: S):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_end = True
    
    def search(self, word: S) -> B:
        node = self.root
        for char in word:
            if char not in node.children:
                return False
            node = node.children[char]
        return node.is_end
    
    def starts_with(self, prefix: S) -> B:
        node = self.root
        for char in prefix:
            if char not in node.children:
                return False
            node = node.children[char]
        return True

# =============================================================================
# ALGORITHM TEMPLATES
# =============================================================================

class BinaryTree:
    """Binary Tree Node and common operations"""
    class Node:
        __slots__ = ['val', 'left', 'right']
        def __init__(self, val: I, left: 'Node' = None, right: 'Node' = None):
            self.val = val
            self.left = left
            self.right = right
    
    @staticmethod
    def inorder(node: 'Node', result: List[I] = None):
        if result is None:
            result = []
        if node:
            BinaryTree.inorder(node.left, result)
            result.append(node.val)
            BinaryTree.inorder(node.right, result)
        return result
    
    @staticmethod
    def preorder(node: 'Node', result: List[I] = None):
        if result is None:
            result = []
        if node:
            result.append(node.val)
            BinaryTree.preorder(node.left, result)
            BinaryTree.preorder(node.right, result)
        return result
    
    @staticmethod
    def postorder(node: 'Node', result: List[I] = None):
        if result is None:
            result = []
        if node:
            BinaryTree.postorder(node.left, result)
            BinaryTree.postorder(node.right, result)
            result.append(node.val)
        return result
    
    @staticmethod
    def level_order(root: 'Node') -> List[List[I]]:
        if not root:
            return []
        result = []
        queue = deque([root])
        while queue:
            level_size = len(queue)
            level = []
            for _ in range(level_size):
                node = queue.popleft()
                level.append(node.val)
                if node.left:
                    queue.append(node.left)
                if node.right:
                    queue.append(node.right)
            result.append(level)
        return result

class GraphAlgorithms:
    """Common graph algorithms"""
    
    @staticmethod
    def bfs(graph: List[List[I]], start: I) -> List[I]:
        """Breadth-First Search"""
        visited = [False] * len(graph)
        distances = [-1] * len(graph)
        queue = deque([start])
        visited[start] = True
        distances[start] = 0
        
        while queue:
            node = queue.popleft()
            for neighbor in graph[node]:
                if not visited[neighbor]:
                    visited[neighbor] = True
                    distances[neighbor] = distances[node] + 1
                    queue.append(neighbor)
        
        return distances
    
    @staticmethod
    def dfs(graph: List[List[I]], start: I) -> List[I]:
        """Depth-First Search"""
        visited = [False] * len(graph)
        result = []
        
        def dfs_recursive(node):
            visited[node] = True
            result.append(node)
            for neighbor in graph[node]:
                if not visited[neighbor]:
                    dfs_recursive(neighbor)
        
        dfs_recursive(start)
        return result
    
    @staticmethod
    def dijkstra(graph: List[List[Tuple[I, I]]], start: I) -> List[I]:
        """Dijkstra's algorithm for shortest path"""
        n = len(graph)
        distances = [LINF] * n
        distances[start] = 0
        heap = [(0, start)]
        
        while heap:
            dist, node = heapq.heappop(heap)
            if dist > distances[node]:
                continue
            for neighbor, weight in graph[node]:
                if distances[neighbor] > distances[node] + weight:
                    distances[neighbor] = distances[node] + weight
                    heapq.heappush(heap, (distances[neighbor], neighbor))
        
        return distances
    
    @staticmethod
    def floyd_warshall(graph: List[List[I]]) -> List[List[I]]:
        """Floyd-Warshall algorithm for all pairs shortest paths"""
        n = len(graph)
        dist = [row[:] for row in graph]
        
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
        
        return dist
    
    @staticmethod
    def kruskal(n: I, edges: List[Tuple[I, I, I]]) -> List[Tuple[I, I, I]]:
        """Kruskal's algorithm for MST"""
        edges.sort(key=lambda x: x[2])
        dsu = DSU(n)
        mst_edges = []
        
        for u, v, weight in edges:
            if dsu.union(u, v):
                mst_edges.append((u, v, weight))
                if len(mst_edges) == n - 1:
                    break
        
        return mst_edges
    
    @staticmethod
    def prim(graph: List[List[Tuple[I, I]]]) -> List[Tuple[I, I, I]]:
        """Prim's algorithm for MST"""
        n = len(graph)
        visited = [False] * n
        heap = [(0, 0, -1)]  # (weight, node, parent)
        mst_edges = []
        total_weight = 0
        
        while heap and len(mst_edges) < n - 1:
            weight, node, parent = heapq.heappop(heap)
            if visited[node]:
                continue
            visited[node] = True
            if parent != -1:
                mst_edges.append((parent, node, weight))
                total_weight += weight
            
            for neighbor, edge_weight in graph[node]:
                if not visited[neighbor]:
                    heapq.heappush(heap, (edge_weight, neighbor, node))
        
        return mst_edges

class StringAlgorithms:
    """Common string algorithms"""
    
    @staticmethod
    def kmp(pattern: S, text: S) -> List[I]:
        """Knuth-Morris-Pratt pattern matching"""
        n, m = len(text), len(pattern)
        lps = StringAlgorithms._build_lps(pattern)
        result = []
        i = j = 0
        
        while i < n:
            if pattern[j] == text[i]:
                i += 1
                j += 1
                if j == m:
                    result.append(i - j)
                    j = lps[j - 1]
            else:
                if j != 0:
                    j = lps[j - 1]
                else:
                    i += 1
        
        return result
    
    @staticmethod
    def _build_lps(pattern: S) -> List[I]:
        """Build LPS array for KMP"""
        m = len(pattern)
        lps = [0] * m
        length = 0
        i = 1
        
        while i < m:
            if pattern[i] == pattern[length]:
                length += 1
                lps[i] = length
                i += 1
            else:
                if length != 0:
                    length = lps[length - 1]
                else:
                    lps[i] = 0
                    i += 1
        
        return lps
    
    @staticmethod
    def manacher(s: S) -> List[I]:
        """Manacher's algorithm for longest palindromic substring"""
        t = '#'.join('^{}$'.format(s))
        n = len(t)
        p = [0] * n
        c = r = 0
        
        for i in range(1, n - 1):
            mirr = 2 * c - i
            if i < r:
                p[i] = min(r - i, p[mirr])
            
            while t[i + (1 + p[i])] == t[i - (1 + p[i])]:
                p[i] += 1
            
            if i + p[i] > r:
                c, r = i, i + p[i]
        
        return p
    
    @staticmethod
    def z_algorithm(s: S) -> List[I]:
        """Z-algorithm for pattern matching"""
        n = len(s)
        z = [0] * n
        l = r = 0
        
        for i in range(1, n):
            if i <= r:
                z[i] = min(r - i + 1, z[i - l])
            
            while i + z[i] < n and s[z[i]] == s[i + z[i]]:
                z[i] += 1
            
            if i + z[i] - 1 > r:
                l, r = i, i + z[i] - 1
        
        return z

# =============================================================================
# DYNAMIC PROGRAMMING HELPERS
# =============================================================================

class DPUtils:
    """Dynamic Programming utilities"""
    
    @staticmethod
    def longest_common_subsequence(a: str, b: str) -> I:
        """LCS length using DP with O(min(n,m)) space"""
        if len(a) < len(b):
            a, b = b, a
        
        prev = [0] * (len(b) + 1)
        for char_a in a:
            curr = [0] * (len(b) + 1)
            for j, char_b in enumerate(b, 1):
                if char_a == char_b:
                    curr[j] = prev[j - 1] + 1
                else:
                    curr[j] = max(prev[j], curr[j - 1])
            prev = curr
        
        return prev[-1]
    
    @staticmethod
    def longest_increasing_subsequence(arr: List[I]) -> I:
        """LIS length using patience sorting O(n log n)"""
        dp = []
        for num in arr:
            idx = bisect.bisect_left(dp, num)
            if idx == len(dp):
                dp.append(num)
            else:
                dp[idx] = num
        return len(dp)
    
    @staticmethod
    def edit_distance(s1: str, s2: str) -> I:
        """Edit distance with O(min(n,m)) space"""
        if len(s1) < len(s2):
            s1, s2 = s2, s1
        
        prev = list(range(len(s2) + 1))
        for i, c1 in enumerate(s1, 1):
            curr = [i] + [0] * len(s2)
            for j, c2 in enumerate(s2, 1):
                if c1 == c2:
                    curr[j] = prev[j - 1]
                else:
                    curr[j] = min(prev[j], curr[j - 1], prev[j - 1]) + 1
            prev = curr
        
        return prev[-1]

# =============================================================================
# GEOMETRY UTILITIES
# =============================================================================

class Geometry:
    """Basic geometry operations"""
    
    @staticmethod
    def cross_product(a: Tuple[I, I], b: Tuple[I, I]) -> I:
        """Cross product of 2D vectors"""
        return a[0] * b[1] - a[1] * b[0]
    
    @staticmethod
    def dot_product(a: Tuple[I, I], b: Tuple[I, I]) -> I:
        """Dot product of 2D vectors"""
        return a[0] * b[0] + a[1] * b[1]
    
    @staticmethod
    def distance(p1: Tuple[I, I], p2: Tuple[I, I]) -> F:
        """Euclidean distance between two points"""
        return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
    
    @staticmethod
    def orientation(p: Tuple[I, I], q: Tuple[I, I], r: Tuple[I, I]) -> I:
        """Find orientation of ordered triplet (p,q,r)"""
        val = Geometry.cross_product((q[0] - p[0], q[1] - p[1]), (r[0] - q[0], r[1] - q[1]))
        if val == 0:
            return 0  # colinear
        return 1 if val > 0 else 2  # clockwise or counterclockwise
    
    @staticmethod
    def convex_hull(points: List[Tuple[I, I]]) -> List[Tuple[I, I]]:
        """Graham scan algorithm for convex hull"""
        points = sorted(points)
        n = len(points)
        if n <= 1:
            return points
        
        # Build lower hull
        lower = []
        for p in points:
            while len(lower) >= 2 and Geometry.cross_product(
                (lower[-1][0] - lower[-2][0], lower[-1][1] - lower[-2][1]),
                (p[0] - lower[-1][0], p[1] - lower[-1][1])
            ) <= 0:
                lower.pop()
            lower.append(p)
        
        # Build upper hull
        upper = []
        for p in reversed(points):
            while len(upper) >= 2 and Geometry.cross_product(
                (upper[-1][0] - upper[-2][0], upper[-1][1] - upper[-2][1]),
                (p[0] - upper[-1][0], p[1] - upper[-1][1])
            ) <= 0:
                upper.pop()
            upper.append(p)
        
        return lower[:-1] + upper[:-1]

# =============================================================================
# HELPER FUNCTIONS
# =============================================================================

def lower_bound(arr: List[int], target: int) -> int:
    """Find first element >= target"""
    return bisect.bisect_left(arr, target)

def upper_bound(arr: List[int], target: int) -> int:
    """Find first element > target"""
    return bisect.bisect_right(arr, target)

def count_inversions(arr: List[I]) -> I:
    """Count inversions using BIT or merge sort"""
    class BIT:
        def __init__(self, size):
            self.tree = [0] * (size + 1)
        
        def update(self, idx):
            while idx <= self.size:
                self.tree[idx] += 1
                idx += idx & -idx
        
        def query(self, idx):
            result = 0
            while idx > 0:
                result += self.tree[idx]
                idx -= idx & -idx
            return result
        
        def __init__(self, size):
            self.size = size
            self.tree = [0] * (size + 1)
    
    # Coordinate compression
    sorted_unique = sorted(set(arr))
    rank = {v: i+1 for i, v in enumerate(sorted_unique)}
    
    bit = BIT(len(sorted_unique))
    inv_count = 0
    for i in reversed(range(len(arr))):
        inv_count += bit.query(rank[arr[i]] - 1)
        bit.update(rank[arr[i]])
    
    return inv_count

def binary_search(arr: List[I], target: I) -> I:
    """Standard binary search"""
    left, right = 0, len(arr) - 1
    result = -1
    while left <= right:
        mid = left + (right - left) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return result
def factorial(n: int) -> int:
    """Calculate factorial"""
    result = 1
    for i in range(1, n+1):
        result *= i
    return result

def factorial_mod(n: int, mod: int) -> int:
    """Calculate factorial modulo mod"""
    result = 1
    for i in range(1, n+1):
        result = (result * i) % mod
    return result

def fibonacci(n: int) -> int:
    """Calculate Fibonacci number by index"""
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a
   

def LMI() -> List[int]:
    """Read multiple integers from input"""
    return list(map(int, input().split()))

def LMF() -> List[float]:
    """Read multiple floats from input"""
    return list(map(float, input().split()))

def LI(n: int) -> List[str]:
    """Read n strings from input"""
    return [input() for _ in range(n)]

def RIM(rows: int, cols: int) -> List[List[int]]:
    """Read a matrix of integers"""
    return [LMI() for _ in range(rows)]

def MII():
    """Read multiple integers from input as a map"""
    return map(int, sys.stdin.readline().split())

def II():
    """Read a single integer from input"""
    return int(sys.stdin.readline())

def FI():
    """Read a single float from input"""
    return float(sys.stdin.readline())

        
def solve() -> None:
    """
    Main solve function
    Replace this with your solution logic
    """
    try:
        input = sys.stdin.readline
        q = int(input())
        while q > 0:
            q -= 1
            a2, a3, a4, b4, b6 = map(int, input().split())
            ans = 0
            while b6 > 0:
                if a3 >= 2:
                    b6 -= 1
                    a3 -= 2
                    ans += 6
                else:
                    break
            while b6 > 0:
                if a4 > 0 and a2 > 0:
                    b6 -= 1
                    a4 -= 1
                    a2 -= 1
                    ans += 6
                else:
                    break
            while b6 > 0:
                if a2 >= 3:
                    b6 -= 1
                    a2 -= 3
                    ans += 6
                else:
                    break
            while b6 > 0:
                if a3 > 0 and a2 > 0:
                    b6 -= 1
                    a3 -= 1
                    a2 -= 1
                    ans += 5
                else:
                    break
            while b6 > 0:
                if a4 > 0:
                    b6 -= 1
                    a4 -= 1
                    ans += 4
                else:
                    break
            if b6 > 0 and a2 == 2:
                ans += 4
                b6 -= 1
                a2 = 0
            if b6 > 0 and a3 > 0:
                ans += 3
                b6 -= 1
                a3 = 0
            if b6 > 0 and a2 > 0:
                ans += 2
                a2 = 0
            while b4 > 0:
                if a4 > 0:
                    b4 -= 1
                    a4 -= 1
                    ans += 4
                else:
                    break
            while b4 > 0:
                if a2 >= 2:
                    b4 -= 1
                    a2 -= 2
                    ans += 4
                else:
                    break
            while b4 > 0:
                if a3 > 0:
                    b4 -= 1
                    a3 -= 1
                    ans += 3
                else:
                    break
            if b4 > 0 and a2 > 0:
                ans += 2
            print(ans)
          
    except (EOFError, KeyboardInterrupt):
        pass

# =============================================================================
# MAIN EXECUTION
# =============================================================================

if __name__ == "__main__":
    # For multiple test cases, uncomment:
    # t = int(input())
    # for _ in range(t):
    #     solve()
    
    # For single test case:
    solve()
# 